#!/usr/bin/perl

use warnings;
use strict;
use FindBin;
use lib "$FindBin::Bin/../lib";
use ReefStats::Schema::ReefStatsDB;

my $schema = ReefStats::Schema::ReefStatsDB->connect_via_config();

my $roles = $schema->resultset('Roles');
#$roles->delete_all();

my $users = $schema->resultset('Users');
#$users->delete_all();

my @roles = qw(administrator domain_administrator standard_user);

for my $role (@roles) {
    $roles->find_or_create( { role => $role } );

    $users->find_or_create(
        {
            email_address => "$role\@example.com",
            password      => $role,
            map_user_role =>
              [ { role => $roles->search( { role => $role } )->first() } ],
        }
    );
}

$schema->txn_commit();

1;
